<?php namespace App\Http\Controllers\Site;

use App\Http\Controllers\Controller;
use App\Item;

class NewsController extends Controller
{
    public function getIndex()
    {
        $lists = Item::where('type','news')->orderBy('kind','ASC')->orderBy('updated_at','DESC')->paginate(10);
        $hots = Item::where('type','news')->orderBy('kind','DESC')->orderBy('updated_at','DESC')->take(20)->get();
        $pros = Item::where('type','product')->orderBy('updated_at','ASC')->take(3)->get();
        return view('site.news.index',[
            'lists' => $lists,
            'hots' => $hots,
            'pros' => $pros,
        ]);
    }

    public function getDetail($id = 0)
    {
        $model = Item::find($id);
        if(0 == $id || "" == $model){
            abort(404);
        }
        $hots = Item::where('type','news')->orderBy('kind','DESC')->orderBy('updated_at','DESC')->take(20)->get();
        $pros = Item::where('type','product')->orderBy('updated_at','ASC')->take(3)->get();
        return view('site.news.detail',[
            'model' => $model,
            'hots' => $hots,
            'pros' => $pros,
        ]);
    }
}